package com.example.elliot.messagesender;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private EditText phoneEdt;
    private EditText messageEdt;
    private Button sendBtn;
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        phoneEdt = (EditText) findViewById(R.id.phoneEdt);
        messageEdt = (EditText) findViewById(R.id.mseeageEdt);
        sendBtn = (Button) findViewById(R.id.sendBtn);

        sendBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String tel_number = phoneEdt.getText().toString().trim();
                String text = messageEdt.getText().toString();

                SmsManager manager = SmsManager.getDefault();
                ArrayList<String> texts = manager.divideMessage(text);

                for (String text1:texts){
                        manager.sendTextMessage(tel_number, null, text1, null, null);
                }
                Toast.makeText(MainActivity.this,"发送成功",Toast.LENGTH_SHORT).show();
            }
        });

    }
}
